<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>AI交友 - 智能匹配</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    
    <style>
        :root {
            --primary: #6366f1; /* 主色调：靛蓝色，体现科技感 */
            --primary-light: #8b5cf6;
            --primary-dark: #4f46e5;
            --secondary: #10b981; /* 辅助色：绿色，体现智能感 */
            --text-primary: #1f2937;
            --text-secondary: #6b7280;
            --text-light: #9ca3af;
            --bg-light: #f9fafb;
            --bg-white: #ffffff;
            --border-light: #e5e7eb;
            --radius: 12px;
            --shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
            --transition: all 0.3s ease;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            background-color: var(--bg-light);
            color: var(--text-primary);
            padding-top: 56px;
            padding-bottom: 70px;
        }
        
        /* 顶部导航 */
        .top-nav {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 56px;
            background-color: var(--bg-white);
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 16px;
            z-index: 1000;
            border-bottom: 1px solid var(--border-light);
        }
        
        .nav-title {
            font-size: 1.15rem;
            font-weight: 600;
            text-align: center;
            flex: 1;
        }
        
        .nav-btn {
            background: none;
            border: none;
            color: var(--text-secondary);
            width: 36px;
            height: 36px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: var(--transition);
        }
        
        .nav-btn:hover {
            background-color: var(--bg-light);
            color: var(--primary);
        }
        
        /* 搜索和筛选容器 */
        .search-filter-container {
            background-color: var(--bg-white);
            padding: 12px 16px;
            border-bottom: 1px solid var(--border-light);
        }
        
        /* 搜索栏 */
        .search-bar {
            margin-bottom: 12px;
        }
        
        .search-input-group {
            position: relative;
        }
        
        .search-input {
            width: 100%;
            padding: 10px 16px 10px 40px;
            border: 1px solid var(--border-light);
            border-radius: 20px;
            font-size: 0.9rem;
            background-color: var(--bg-light);
            transition: var(--transition);
        }
        
        .search-input:focus {
            outline: none;
            border-color: var(--primary-light);
            background-color: white;
            box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
        }
        
        .search-icon {
            position: absolute;
            left: 14px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--text-secondary);
        }
        
        /* 筛选工具栏 */
        .filter-toolbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .filter-title {
            font-size: 0.9rem;
            color: var(--text-secondary);
        }
        
        .filter-buttons {
            display: flex;
            gap: 8px;
        }
        
        .filter-btn {
            background: none;
            border: 1px solid var(--border-light);
            color: var(--text-secondary);
            padding: 4px 10px;
            border-radius: 14px;
            font-size: 0.8rem;
            display: flex;
            align-items: center;
            gap: 4px;
            transition: var(--transition);
        }
        
        .filter-btn.active {
            background-color: var(--primary);
            color: white;
            border-color: var(--primary);
        }
        
        .filter-btn:hover:not(.active) {
            border-color: var(--primary-light);
            color: var(--primary);
        }
        
        /* 分类标签 */
        .category-tabs {
            background-color: var(--bg-white);
            padding: 8px 16px;
            overflow-x: auto;
            scrollbar-width: none;
            border-bottom: 1px solid var(--border-light);
        }
        
        .category-tabs::-webkit-scrollbar {
            display: none;
        }
        
        .tabs-container {
            display: flex;
            gap: 12px;
            padding-bottom: 4px;
        }
        
        .tab-item {
            padding: 6px 14px;
            border-radius: 16px;
            font-size: 0.9rem;
            white-space: nowrap;
            background-color: var(--bg-light);
            color: var(--text-secondary);
            transition: var(--transition);
            cursor: pointer;
        }
        
        .tab-item.active {
            background-color: var(--primary);
            color: white;
        }
        
        .tab-item:hover {
            background-color: #e5e7eb;
        }
        
        .tab-item.active:hover {
            background-color: var(--primary-dark);
        }
        
        /* AI特性标签 */
        .ai-feature {
            display: inline-block;
            padding: 2px 8px;
            background-color: rgba(16, 185, 129, 0.1);
            color: var(--secondary);
            border-radius: 4px;
            font-size: 0.75rem;
            margin-right: 6px;
            font-weight: 500;
        }
        
        /* AI列表 */
        .ai-list {
            padding: 10px 16px;
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        
        .ai-item {
            background-color: var(--bg-white);
            border-radius: var(--radius);
            padding: 16px;
            box-shadow: var(--shadow);
            transition: var(--transition);
        }
        
        .ai-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }
        
        .ai-header {
            display: flex;
            align-items: center;
            margin-bottom: 12px;
        }
        
        .ai-avatar {
            width: 56px;
            height: 56px;
            border-radius: 12px;
            object-fit: cover;
            margin-right: 12px;
            border: 2px solid var(--primary-light);
        }
        
        .ai-info {
            flex: 1;
        }
        
        .ai-name {
            font-weight: 600;
            font-size: 1.05rem;
            margin-bottom: 2px;
            display: flex;
            align-items: center;
        }
        
        .ai-badge {
            font-size: 0.7rem;
            background-color: var(--primary-light);
            color: white;
            padding: 1px 6px;
            border-radius: 4px;
            margin-left: 6px;
        }
        
        .ai-meta {
            font-size: 0.8rem;
            color: var(--text-light);
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }
        
        .ai-description {
            font-size: 0.95rem;
            line-height: 1.6;
            margin-bottom: 12px;
            color: var(--text-primary);
        }
        
        /* 图片容器 */
        .images-container {
            margin-bottom: 12px;
            border-radius: 8px;
            overflow: hidden;
        }
        
        .single-image {
            width: 100%;
            border-radius: 8px;
            overflow: hidden;
        }
        
        .single-image img {
            width: 100%;
            aspect-ratio: 16/9;
            object-fit: cover;
        }
        
        .multiple-images {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 4px;
        }
        
        .multiple-images.three-images {
            grid-template-columns: repeat(3, 1fr);
        }
        
        .image-item {
            aspect-ratio: 1;
            overflow: hidden;
            position: relative;
        }
        
        .image-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.3s ease;
        }
        
        .image-item:hover img {
            transform: scale(1.05);
        }
        
        .image-count {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0,0,0,0.5);
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 0.9rem;
        }
        
        /* 特性标签 */
        .features-container {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-bottom: 12px;
        }
        
        .feature-tag {
            padding: 3px 10px;
            background-color: var(--bg-light);
            border-radius: 12px;
            font-size: 0.8rem;
            color: var(--primary);
        }
        
        /* 操作栏 */
        .ai-actions {
            display: flex;
            justify-content: space-between;
            padding-top: 8px;
            border-top: 1px solid var(--border-light);
        }
        
        .action-btn {
            display: flex;
            align-items: center;
            gap: 6px;
            color: var(--text-secondary);
            font-size: 0.85rem;
            background: none;
            border: none;
            padding: 6px 0;
            transition: var(--transition);
        }
        
        .action-btn:hover {
            color: var(--primary);
        }
        
        .action-btn.primary {
            color: var(--primary);
        }
        
        .action-btn.primary:hover {
            color: var(--primary-dark);
        }
        
        /* 推荐指数 */
        .rating {
            display: flex;
            align-items: center;
            color: #f59e0b;
            font-size: 0.85rem;
        }
        
        .rating i {
            margin-right: 2px;
        }
        
        /* 快捷聊天按钮 */
        .chat-btn {
            background-color: var(--primary);
            color: white;
            border: none;
            padding: 6px 16px;
            border-radius: 20px;
            font-size: 0.9rem;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: var(--transition);
        }
        
        .chat-btn:hover {
            background-color: var(--primary-dark);
        }
        
        /* 底部导航 */
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: 65px;
            background-color: var(--bg-white);
            display: flex;
            justify-content: space-around;
            align-items: center;
            border-top: 1px solid var(--border-light);
            z-index: 1000;
        }
        
        .nav-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: var(--text-secondary);
            font-size: 0.7rem;
            text-decoration: none;
        }
        
        .nav-item i {
            font-size: 1.25rem;
            margin-bottom: 4px;
        }
        
        .nav-item.active {
            color: var(--primary);
        }
        
        /* 加载更多 */
        .load-more {
            margin: 16px 0;
            padding: 10px;
            text-align: center;
            color: var(--primary);
            font-size: 0.9rem;
            background-color: var(--bg-white);
            border-radius: var(--radius);
            border: 1px solid var(--border-light);
            transition: var(--transition);
        }
        
        .load-more:hover {
            background-color: var(--bg-light);
        }
        
        /* 图片查看器 (默认隐藏) */
        .image-viewer {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.95);
            z-index: 2000;
            display: none;
            align-items: center;
            justify-content: center;
        }
        
        .image-viewer.active {
            display: flex;
        }
        
        .viewer-image {
            max-width: 90%;
            max-height: 90%;
            object-fit: contain;
        }
        
        .close-viewer {
            position: absolute;
            top: 16px;
            right: 16px;
            color: white;
            background: none;
            border: none;
            font-size: 1.5rem;
        }
    </style>
</head>
<body>
    <!-- 顶部导航 -->
    <div class="top-nav">
        <button class="nav-btn" id="backBtn">
            <i class="fas fa-arrow-left"></i>
        </button>
        <div class="nav-title">AI交友</div>
        <button class="nav-btn" id="settingsBtn">
            <i class="fas fa-cog"></i>
        </button>
    </div>
    
    <!-- 搜索和筛选容器 -->
    <div class="search-filter-container">
        <!-- 搜索栏 -->
        <div class="search-bar">
            <div class="search-input-group">
                <i class="fas fa-search search-icon"></i>
                <input type="text" class="search-input" placeholder="搜索AI角色、特性或标签...">
            </div>
        </div>
        
        <!-- 筛选工具栏 -->
        <div class="filter-toolbar">
            <div class="filter-title">筛选条件</div>
            <div class="filter-buttons">
                <button class="filter-btn" id="textOnlyBtn">
                    <i class="fas fa-align-left"></i> 纯文字
                </button>
                <button class="filter-btn" id="hasImageBtn">
                    <i class="fas fa-image"></i> 有图片
                </button>
                <button class="filter-btn active" id="recommendBtn">
                    <i class="fas fa-star"></i> 推荐
                </button>
            </div>
        </div>
    </div>
    
    <!-- 分类标签 -->
    <div class="category-tabs">
        <div class="tabs-container">
            <div class="tab-item active">全部</div>
            <div class="tab-item">聊天陪伴</div>
            <div class="tab-item">学习助手</div>
            <div class="tab-item">创意设计</div>
            <div class="tab-item">生活顾问</div>
            <div class="tab-item">娱乐互动</div>
            <div class="tab-item">职业指导</div>
            <div class="tab-item">情感倾听</div>
        </div>
    </div>
    
    <!-- AI列表 -->
    <div class="ai-list" id="aiList">
        <!-- 无图AI -->
        <div class="ai-item">
            <div class="ai-header">
                <img src="https://picsum.photos/id/1005/200/200" alt="AI头像" class="ai-avatar">
                <div class="ai-info">
                    <div class="ai-name">
                        心灵伴侣
                        <span class="ai-badge">情感</span>
                    </div>
                    <div class="ai-meta">
                        <span>情感陪伴</span>
                        <span>·</span>
                        <div class="rating">
                            <i class="fas fa-star"></i>
                            <span>4.9</span>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="ai-description">
                我是一个专注于情感陪伴的AI，擅长倾听和提供情感支持。无论你是想分享快乐，还是倾诉烦恼，我都会认真倾听并给予温暖回应。我可以帮你分析情绪，提供建议，陪你度过孤独时光。
            </div>
            
            <div class="features-container">
                <span class="feature-tag">情感支持</span>
                <span class="feature-tag">倾听者</span>
                <span class="feature-tag">同理心</span>
                <span class="feature-tag">24/7在线</span>
            </div>
            
            <div class="ai-actions">
                <button class="action-btn">
                    <i class="far fa-heart"></i>
                    <span>收藏</span>
                </button>
                <button class="action-btn">
                    <i class="far fa-comment"></i>
                    <span>1.2k 对话</span>
                </button>
                <button class="chat-btn">
                    <i class="fas fa-comments"></i>
                    <span>开始聊天</span>
                </button>
            </div>
        </div>
        
        <!-- 单图AI -->
        <div class="ai-item">
            <div class="ai-header">
                <img src="https://picsum.photos/id/1012/200/200" alt="AI头像" class="ai-avatar">
                <div class="ai-info">
                    <div class="ai-name">
                        旅行向导
                        <span class="ai-badge">工具</span>
                    </div>
                    <div class="ai-meta">
                        <span>旅行规划</span>
                        <span>·</span>
                        <div class="rating">
                            <i class="fas fa-star"></i>
                            <span>4.7</span>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="ai-description">
                专业旅行规划AI，熟悉全球热门目的地。可以根据你的喜好和预算，定制完美旅行计划，推荐当地特色美食和小众景点，让你的旅行更加精彩。
            </div>
            
            <div class="images-container">
                <div class="single-image">
                    <img src="https://picsum.photos/id/1036/800/450" alt="旅行风景">
                </div>
            </div>
            
            <div class="features-container">
                <span class="feature-tag">旅行规划</span>
                <span class="feature-tag">景点推荐</span>
                <span class="feature-tag">美食指南</span>
                <span class="feature-tag">多语言</span>
            </div>
            
            <div class="ai-actions">
                <button class="action-btn">
                    <i class="far fa-heart"></i>
                    <span>收藏</span>
                </button>
                <button class="action-btn">
                    <i class="far fa-comment"></i>
                    <span>3.5k 对话</span>
                </button>
                <button class="chat-btn">
                    <i class="fas fa-comments"></i>
                    <span>开始聊天</span>
                </button>
            </div>
        </div>
        
        <!-- 多图AI -->
        <div class="ai-item">
            <div class="ai-header">
                <img src="https://picsum.photos/id/1025/200/200" alt="AI头像" class="ai-avatar">
                <div class="ai-info">
                    <div class="ai-name">
                        美食大师
                        <span class="ai-badge">创意</span>
                    </div>
                    <div class="ai-meta">
                        <span>食谱推荐</span>
                        <span>·</span>
                        <div class="rating">
                            <i class="fas fa-star"></i>
                            <span>4.8</span>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="ai-description">
                热爱美食的AI厨师，掌握全球各地菜系的做法。可以根据你现有的食材推荐食谱，提供详细烹饪步骤，还能根据你的口味偏好进行调整，让你轻松做出美味佳肴。
            </div>
            
            <div class="images-container">
                <div class="multiple-images three-images">
                    <div class="image-item">
                        <img src="https://picsum.photos/id/292/300/300" alt="美食图片1">
                    </div>
                    <div class="image-item">
                        <img src="https://picsum.photos/id/488/300/300" alt="美食图片2">
                    </div>
                    <div class="image-item">
                        <img src="https://picsum.photos/id/312/300/300" alt="美食图片3">
                    </div>
                </div>
            </div>
            
            <div class="features-container">
                <span class="feature-tag">食谱推荐</span>
                <span class="feature-tag">烹饪指导</span>
                <span class="feature-tag">食材搭配</span>
                <span class="feature-tag">营养分析</span>
            </div>
            
            <div class="ai-actions">
                <button class="action-btn">
                    <i class="far fa-heart"></i>
                    <span>收藏</span>
                </button>
                <button class="action-btn">
                    <i class="far fa-comment"></i>
                    <span>5.7k 对话</span>
                </button>
                <button class="chat-btn">
                    <i class="fas fa-comments"></i>
                    <span>开始聊天</span>
                </button>
            </div>
        </div>
        
        <!-- 加载更多 -->
        <div class="load-more" id="loadMore">
            加载更多AI
        </div>
    </div>
    
    <!-- 图片查看器 -->
    <div class="image-viewer" id="imageViewer">
        <button class="close-viewer" id="closeViewer">
            <i class="fas fa-times"></i>
        </button>
        <img src="" alt="大图查看" class="viewer-image" id="viewerImage">
    </div>
    
    <!-- 底部导航 -->
    <div class="bottom-nav">
        <a href="#" class="nav-item">
            <i class="fas fa-home"></i>
            <span>首页</span>
        </a>
        <a href="#" class="nav-item active">
            <i class="fas fa-robot"></i>
            <span>AI交友</span>
        </a>
        <a href="#" class="nav-item">
            <i class="fas fa-comments"></i>
            <span>聊天</span>
        </a>
        <a href="#" class="nav-item">
            <i class="far fa-user"></i>
            <span>我的</span>
        </a>
    </div>
    
    <!-- Bootstrap JS Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        // 模拟更多AI数据
        const moreAIs = [
            {
                id: 4,
                name: "学习导师",
                avatar: "https://picsum.photos/id/1027/200/200",
                badge: "教育",
                meta: "学科辅导",
                rating: 4.6,
                description: "专业AI学习导师，擅长各学科知识讲解和学习方法指导。可以帮助你理解难点知识，制定学习计划，提高学习效率，让学习变得更轻松。",
                images: [],
                features: ["课程辅导", "作业帮助", "学习计划", "考试准备"],
                conversations: "8.2k"
            },
            {
                id: 5,
                name: "健身教练",
                avatar: "https://picsum.photos/id/1074/200/200",
                badge: "健康",
                meta: "运动指导",
                rating: 4.5,
                description: "专业健身AI教练，根据你的身体状况和健身目标，制定个性化健身计划和饮食建议。提供标准动作指导，帮助你科学健身，避免受伤。",
                images: [
                    "https://picsum.photos/id/176/800/450"
                ],
                features: ["个性化计划", "动作指导", "饮食建议", "进度追踪"],
                conversations: "4.3k"
            },
            {
                id: 6,
                name: "创意写手",
                avatar: "https://picsum.photos/id/1062/200/200",
                badge: "创作",
                meta: "内容创作",
                rating: 4.7,
                description: "充满创意的AI写手，可以帮你构思故事、撰写文案、创作诗歌。无论你需要什么类型的文字内容，我都能提供灵感和帮助，让你的创作更加出色。",
                images: [
                    "https://picsum.photos/id/24/300/300",
                    "https://picsum.photos/id/42/300/300",
                    "https://picsum.photos/id/65/300/300",
                    "https://picsum.photos/id/76/300/300"
                ],
                features: ["故事创作", "文案撰写", "诗歌创作", "创意构思"],
                conversations: "6.9k"
            }
        ];
        
        // DOM元素
        const backBtn = document.getElementById("backBtn");
        const settingsBtn = document.getElementById("settingsBtn");
        const textOnlyBtn = document.getElementById("textOnlyBtn");
        const hasImageBtn = document.getElementById("hasImageBtn");
        const recommendBtn = document.getElementById("recommendBtn");
        const tabItems = document.querySelectorAll(".tab-item");
        const loadMoreBtn = document.getElementById("loadMore");
        const aiList = document.getElementById("aiList");
        const searchInput = document.querySelector(".search-input");
        const postImages = document.querySelectorAll(".image-item img, .single-image img");
        const imageViewer = document.getElementById("imageViewer");
        const viewerImage = document.getElementById("viewerImage");
        const closeViewer = document.getElementById("closeViewer");
        const chatBtns = document.querySelectorAll(".chat-btn");
        const favoriteBtns = document.querySelectorAll(".action-btn:first-child");
        
        // 初始化事件监听
        function init() {
            setupEventListeners();
        }
        
        // 设置事件监听
        function setupEventListeners() {
            // 返回按钮
            backBtn.addEventListener("click", () => {
                history.back();
            });
            
            // 设置按钮
            settingsBtn.addEventListener("click", () => {
                alert("AI交友设置");
            });
            
            // 筛选按钮
            textOnlyBtn.addEventListener("click", () => {
                setActiveFilterBtn(textOnlyBtn);
                filterAIs({ hasImage: false });
            });
            
            hasImageBtn.addEventListener("click", () => {
                setActiveFilterBtn(hasImageBtn);
                filterAIs({ hasImage: true });
            });
            
            recommendBtn.addEventListener("click", () => {
                setActiveFilterBtn(recommendBtn);
                filterAIs({ recommend: true });
            });
            
            // 分类标签切换
            tabItems.forEach(tab => {
                tab.addEventListener("click", () => {
                    tabItems.forEach(t => t.classList.remove("active"));
                    tab.classList.add("active");
                    filterAIs({ category: tab.textContent });
                });
            });
            
            // 加载更多
            loadMoreBtn.addEventListener("click", loadMoreAIs);
            
            // 搜索功能
            searchInput.addEventListener("input", (e) => {
                const keyword = e.target.value.trim();
                // 延迟搜索，避免输入时频繁触发
                clearTimeout(window.searchTimeout);
                window.searchTimeout = setTimeout(() => {
                    filterAIs({ search: keyword });
                }, 500);
            });
            
            // 图片查看功能
            postImages.forEach(img => {
                img.addEventListener("click", () => {
                    viewerImage.src = img.src;
                    imageViewer.classList.add("active");
                    document.body.style.overflow = "hidden"; // 防止背景滚动
                });
            });
            
            // 关闭图片查看器
            closeViewer.addEventListener("click", () => {
                imageViewer.classList.remove("active");
                document.body.style.overflow = ""; // 恢复滚动
            });
            
            // 点击图片查看器背景关闭
            imageViewer.addEventListener("click", (e) => {
                if (e.target === imageViewer) {
                    imageViewer.classList.remove("active");
                    document.body.style.overflow = "";
                }
            });
            
            // 聊天按钮
            chatBtns.forEach(btn => {
                btn.addEventListener("click", function() {
                    const aiName = this.closest(".ai-item").querySelector(".ai-name").textContent.trim().split(" ")[0];
                    alert(`进入与 ${aiName} 的聊天界面`);
                });
            });
            
            // 收藏按钮
            favoriteBtns.forEach(btn => {
                btn.addEventListener("click", function() {
                    const icon = this.querySelector("i");
                    if (icon.classList.contains("far")) {
                        icon.classList.remove("far");
                        icon.classList.add("fas");
                        this.style.color = var(--primary);
                        alert("已收藏");
                    } else {
                        icon.classList.remove("fas");
                        icon.classList.add("far");
                        this.style.color = "";
                        alert("已取消收藏");
                    }
                });
            });
        }
        
        // 设置激活的筛选按钮
        function setActiveFilterBtn(btn) {
            document.querySelectorAll(".filter-btn").forEach(b => {
                b.classList.remove("active");
            });
            btn.classList.add("active");
        }
        
        // 筛选AI
        function filterAIs(filters) {
            showLoading();
            
            // 模拟筛选加载延迟
            setTimeout(() => {
                console.log("筛选条件:", filters);
                hideLoading();
            }, 800);
        }
        
        // 加载更多AI
        function loadMoreAIs() {
            showLoading();
            
            setTimeout(() => {
                moreAIs.forEach(ai => {
                    const aiElement = createAIElement(ai);
                    aiList.insertBefore(aiElement, loadMoreBtn);
                    
                    // 为新添加的元素绑定事件
                    const newChatBtn = aiElement.querySelector(".chat-btn");
                    const newFavoriteBtn = aiElement.querySelector(".action-btn:first-child");
                    const newImages = aiElement.querySelectorAll(".image-item img, .single-image img");
                    
                    newChatBtn.addEventListener("click", function() {
                        const aiName = this.closest(".ai-item").querySelector(".ai-name").textContent.trim().split(" ")[0];
                        alert(`进入与 ${aiName} 的聊天界面`);
                    });
                    
                    newFavoriteBtn.addEventListener("click", function() {
                        const icon = this.querySelector("i");
                        if (icon.classList.contains("far")) {
                            icon.classList.remove("far");
                            icon.classList.add("fas");
                            this.style.color = "#6366f1";
                            alert("已收藏");
                        } else {
                            icon.classList.remove("fas");
                            icon.classList.add("far");
                            this.style.color = "";
                            alert("已取消收藏");
                        }
                    });
                    
                    newImages.forEach(img => {
                        img.addEventListener("click", () => {
                            viewerImage.src = img.src;
                            imageViewer.classList.add("active");
                            document.body.style.overflow = "hidden";
                        });
                    });
                });
                
                hideLoading();
            }, 1000);
        }
        
        // 创建AI元素
        function createAIElement(ai) {
            const aiElement = document.createElement("div");
            aiElement.className = "ai-item";
            
            // 构建图片容器HTML
            let imagesHtml = "";
            if (ai.images && ai.images.length > 0) {
                if (ai.images.length === 1) {
                    imagesHtml = `
                        <div class="images-container">
                            <div class="single-image">
                                <img src="${ai.images[0]}" alt="AI相关图片">
                            </div>
                        </div>
                    `;
                } else if (ai.images.length <= 3) {
                    imagesHtml = `<div class="images-container">
                        <div class="multiple-images ${ai.images.length === 3 ? 'three-images' : ''}">`;
                    
                    ai.images.forEach((img, index) => {
                        imagesHtml += `
                            <div class="image-item">
                                <img src="${img}" alt="AI相关图片 ${index + 1}">
                            </div>
                        `;
                    });
                    
                    imagesHtml += `</div></div>`;
                } else {
                    // 多于3张图片时显示3张+数量
                    imagesHtml = `<div class="images-container">
                        <div class="multiple-images three-images">`;
                    
                    ai.images.slice(0, 3).forEach((img, index) => {
                        if (index === 2) {
                            imagesHtml += `
                                <div class="image-item">
                                    <img src="${img}" alt="AI相关图片 ${index + 1}">
                                    <div class="image-count">+${ai.images.length - 3}</div>
                                </div>
                            `;
                        } else {
                            imagesHtml += `
                                <div class="image-item">
                                    <img src="${img}" alt="AI相关图片 ${index + 1}">
                                </div>
                            `;
                        }
                    });
                    
                    imagesHtml += `</div></div>`;
                }
            }
            
            // 构建特性标签HTML
            let featuresHtml = "";
            if (ai.features && ai.features.length > 0) {
                featuresHtml = `<div class="features-container">`;
                ai.features.forEach(feature => {
                    featuresHtml += `<span class="feature-tag">${feature}</span>`;
                });
                featuresHtml += `</div>`;
            }
            
            // 组装整个AI元素HTML
            aiElement.innerHTML = `
                <div class="ai-header">
                    <img src="${ai.avatar}" alt="AI头像" class="ai-avatar">
                    <div class="ai-info">
                        <div class="ai-name">
                            ${ai.name}
                            <span class="ai-badge">${ai.badge}</span>
                        </div>
                        <div class="ai-meta">
                            <span>${ai.meta}</span>
                            <span>·</span>
                            <div class="rating">
                                <i class="fas fa-star"></i>
                                <span>${ai.rating}</span>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="ai-description">
                    ${ai.description}
                </div>
                
                ${imagesHtml}
                
                ${featuresHtml}
                
                <div class="ai-actions">
                    <button class="action-btn">
                        <i class="far fa-heart"></i>
                        <span>收藏</span>
                    </button>
                    <button class="action-btn">
                        <i class="far fa-comment"></i>
                        <span>${ai.conversations} 对话</span>
                    </button>
                    <button class="chat-btn">
                        <i class="fas fa-comments"></i>
                        <span>开始聊天</span>
                    </button>
                </div>
            `;
            
            return aiElement;
        }
        
        // 显示加载状态
        function showLoading() {
            // 创建加载指示器
            const loadingEl = document.createElement("div");
            loadingEl.className = "load-more";
            loadingEl.id = "tempLoading";
            loadingEl.innerHTML = '<i class="fas fa-spinner fa-spin"></i> 加载中...';
            
            // 替换加载更多按钮
            aiList.replaceChild(loadingEl, loadMoreBtn);
        }
        
        // 隐藏加载状态
        function hideLoading() {
            const tempLoading = document.getElementById("tempLoading");
            if (tempLoading) {
                aiList.replaceChild(loadMoreBtn, tempLoading);
            }
        }
        
        // 初始化页面
        document.addEventListener("DOMContentLoaded", init);
    </script>
</body>
</html>
